package com.javaee.response;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@WebServlet("/paramsservletplus")
public class ParamsServletPlus extends HttpServlet {

	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		this.doPost(req, resp);
	}

	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

		req.setCharacterEncoding("utf-8");
		resp.setContentType("text/html;charset=utf-8");
		
		String[] hobbis = req.getParameterValues("hobby");
		StringBuffer sb = new StringBuffer();
		String str = null;
		if (hobbis == null) {
			sb.append("您没有选择相应的爱好");
			str = sb.toString();
		} else {
			for (int i = 0; i < hobbis.length; i++) {
				sb.append(hobbis[i]+",");
			}
			// 处理最后一个逗号
			str = sb.substring(0, sb.length()-1);
		}
		resp.getWriter().println("爱好情况：<br>");
		resp.getWriter().println(str);
				
				
	}

}
